/*
 * Copyright (c) 2008, Xiong Yingfei, the University of Tokyo
 * All rights reserved.
 */
package ac.jp.u_tokyo.SyncLib.language2;

import java.util.Collection;

import ac.jp.u_tokyo.SyncLib.language.EvaluationFailedException;

public class Var
{
	private String _name;
	private int _line;

	public String getName()
	{
		return _name;
	}

	public int getLine()
	{
		return _line;
	}

	public Var(String name, int line)
	{
		super();
		_name = name;
		_line = line;
	}
	
	public void check(Collection<String> genericParas) throws EvaluationFailedException{
		if (genericParas.contains(_name))
			throw new ExpectingAttributeName(_name, _line);
	}
	
	public String checkAndGetName(Collection<String> genericParas) throws EvaluationFailedException{
		if (genericParas.contains(_name))
			throw new ExpectingAttributeName(_name, _line);
		return _name;
	}

	@Override
	public String toString()
	{
		return _name;
	}

	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + ((_name == null) ? 0 : _name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj)
	{
		if (this == obj) return true;
		if (obj == null) return false;
		if (getClass() != obj.getClass()) return false;
		final Var other = (Var) obj;
		if (_name == null)
		{
			if (other._name != null) return false;
		}
		else if (!_name.equals(other._name)) return false;
		return true;
	}
	
	
}
